import 'package:flutter/material.dart';

class StaggerAnimation extends StatelessWidget {
  StaggerAnimation({super.key, required this.controller}) {
    // 高度动画
    height = Tween<double>(begin: 0.0, end: 300.0).animate(
      CurvedAnimation(
        parent: controller,
        curve: Interval(
          0.0,
          0.6, // 间隔，前60%的动画时间
          curve: Curves.ease,
        ),
      ),
    );

    // 颜色动画，确保 begin 和 end 非空
    color = ColorTween(
      begin: Colors.green, // 非空颜色值
      end: Colors.red, // 非空颜色值
    ).animate(
      CurvedAnimation(
        parent: controller,
        curve: Interval(
          0.0,
          0.6, // 间隔，前60%的动画时间
          curve: Curves.ease,
        ),
      ),
    );

    // 内边距动画
    padding = Tween<EdgeInsets>(
      begin: EdgeInsets.only(left: 0.0),
      end: EdgeInsets.only(left: 100.0),
    ).animate(
      CurvedAnimation(
        parent: controller,
        curve: Interval(
          0.6,
          1.0, // 间隔，后40%的动画时间
          curve: Curves.ease,
        ),
      ),
    );
  }

  final Animation<double> controller;
  late final Animation<double> height;
  late final Animation<EdgeInsets> padding;
  late final Animation<Color?> color; // 使用 Color? 以兼容 null-safety

  Widget _buildAnimation(BuildContext context, Widget? child) {
    return Container(
      alignment: Alignment.bottomCenter,
      padding: padding.value,
      child: Container(
        color: color.value, // 使用 color.value
        width: 50.0,
        height: height.value,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      builder: _buildAnimation, // 修复后符合 TransitionBuilder 类型
      animation: controller,
    );
  }
}
